home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
idemo
/
nodos.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-26
|
5KB
|
191 lines
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/*** nodos.c ***/
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/tasks.h>
#include <exec/memory.h>
putc(c)
int c;
{
KPutChar(c);
}
PutChar(c)
int c;
{
KPutChar(c);
}
MayGetChar()
{
return(KMayGetChar());
}
MayGetCh()
{
return(KMayGetChar());
}
printf(a,b,c,d,e,f,g,h,i,j,k)
{
kprintf(a,b,c,d,e,f,g,h,i,j,k);
}
int getmem(a)
int a;
{
return (AllocMem(a,MEMF_CHIP));
}
int GetNum()
{
int c,n;
int sign = 1;
n = 0;
while ( (c = KGetChar()) != '\r')
{
putc(c);
switch(c)
{
case '-' : sign = -sign;
break;
case '\b' : n = n/10;
break;
case 'q' : exit();
default : n = n*10 + c - '0';
}
}
return(sign*n);
}
Panic(s)
char *s;
{
printf("%s\n",s);
}
/*** pio.c ***/
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/memory.h"
#include "exec/ports.h"
#include "exec/libraries.h"
#include "exec/devices.h"
#include "exec/tasks.h"
#include "exec/io.h"
#include "exec/interrupts.h"
#include "devices/printer.h"
union
{
struct IOStdReq ios;
struct IODRPReq iodrp;
struct IOPrtCmdReq iopc;
} printerIO;
struct MsgPort replyMsgPort;
/* ======================================================================== */
/* ======================================================================== */
/* ======================================================================== */
int PrinterOpen(signal) /* open the printer */
int signal;
{
int error;
/* open the printer device */
if ((error = OpenDevice("printer.device", 0, &printerIO, 0)) != 0)
{
printf("EventInit \"printer.device\" OpenDevice error: %d.\n", error);
return(error);
}
printf("printer.device: %lx.\n", printerIO.ios.io_Device);
/* set up the message port in the I/O request */
replyMsgPort.mp_Node.ln_Type = NT_MSGPORT;
replyMsgPort.mp_Flags = 0;
if (signal >= 0)
{
printf("Printer signal: %ld\n", signal);
replyMsgPort.mp_SigBit = signal;
replyMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
}
else
{
printf("Warning. printer set up for immediate I/O only.\n");
replyMsgPort.mp_SigBit = 0;
replyMsgPort.mp_SigTask = 0;
}
AddPort(&replyMsgPort);
printerIO.ios.io_Message.mn_ReplyPort = &replyMsgPort;
return(0);
}
PrinterClose() /* close the printer */
{
CloseDevice(&printerIO);
RemPort(&replyMsgPort);
}
/* the dump to printer caller */
VOID PrintRPort(rastPort, colorMap, modes, sx,sy, sw,sh, dc,dr, special)
struct RastPort *rastPort;
UWORD *colorMap;
ULONG modes;
int sx, sy, sw, sh, dc, dr;
UWORD special;
{
printerIO.iodrp.io_Command = PRD_DUMPRPORT;
printerIO.iodrp.io_RastPort = rastPort;
printerIO.iodrp.io_ColorMap = colorMap;
printerIO.iodrp.io_Modes = modes;
printerIO.iodrp.io_SrcX = sx;
printerIO.iodrp.io_SrcY = sy;
printerIO.iodrp.io_SrcWidth = sw;
printerIO.iodrp.io_SrcHeight = sh;
printerIO.iodrp.io_DestCols = dc;
printerIO.iodrp.io_DestRows = dr;
printerIO.iodrp.io_Special = special;
DoIO(&printerIO);
}
VOID pWrite(buffer) /* write to the printer */
char *buffer;
{
int count;
char *b;
b = buffer;
count = 0;
while (*b++ != '\0') count++;
/* queue a printer write */
printerIO.ios.io_Command = CMD_WRITE;
printerIO.ios.io_Data = buffer;
printerIO.ios.io_Length = count;
DoIO(&printerIO);
}